﻿EmployeeList = Class.create();

EmployeeList.prototype = Object.extend(new Common(), {
    initialize: function () {
        this.initCommonProperty();

        this.employeeInputIns = null;
    },

    init: function () {
        //查找员工信息
        Event.observe($("btnSearch"), 'click', this.onClick_search.bind(this));

        //添加员工信息
        Event.observe($("btnAdd"), 'click', this.onClick_insertEmployee.bind(this));

        //删除员工信息
        Event.observe($("btnDelete"), 'click', this.onClick_Delete.bind(this));

        //清空员查询条件
        Event.observe($("btnClear"), 'click', this.onClick_Clear.bind(this));

        //定义head的显示
        this.colList = new Array();

        //定义tableIns实例
        this.tableIns = new Table();

        //显示多选框
        this.tableIns.useCheckOne = true;

        this.tableIns.pkColumnName = "employee_id";

        //显示条数
        this.tableIns.setPageSize(13);

        //定义head的显示
        this.initTableColList();

        this.getEmployeeList();
    },
    //定义head的显示
    initTableColList: function () {
        this.colList.push(new ColInfo("帐号", "employee_code", "10%", SORT_YES, ALIGN_CENTER));
        this.colList.push(new ColInfo("名字", "employee_name", "10%", SORT_YES, ALIGN_CENTER));
        this.colList.push(new ColInfo("职位", "position_name", "10%"));
        this.colList.push(new ColInfo("电话/手机", "employee_phone", "10%"));
        this.colList.push(new ColInfo("邮件", "employee_email", "20%"));
        this.colList.push(new ColInfo("地址", "employee_address", "20%"));
        this.colList.push(new ColInfo("创建者", "create_user", "10%"));
        this.colList.push(new ColInfo("修改者", "update_user", "10%"));
    },
    onClick_Clear: function () {
        this.clearForm();
    },
    //得到员工信息
    getEmployeeList: function () {
        var data = this.getListCondition(this.getSearchModel(), this.tableIns.pager);
        CmnMessage.showProcessing();
        this.sendAjaxBySearchCondition("/Master/GetEmployeeList", data, this.getEmployeeListCallback.bind(this));
    },
    getEmployeeListCallback: function (response) {
        var json = this.jsonParse(response);

        this.tableIns.init("employeeList", json, this.colList, this.cellCallback.bind(this));

        this.tableIns.changePageCallback = this.getEmployeeList.bind(this);

        this.tableIns.clientSortCallback = this.getEmployeeList.bind(this);

        this.tableIns.rowClassCallback = this.setRowClass.bind(this);

        this.tableIns.create();

        CmnMessage.hide();
    },
    onClick_insertEmployee: function () {
        this.employeeInputIns.show(this.getEmployeeList.bind(this));
    },
    //删除処理
    onClick_Delete: function () {
        //是否选中行
        if (this.tableIns.checkedDataList.length <= 0) {
            CmnMessage.showMessage("没有选中任何行!", MSG_TYPE_INFO);
        }
        else {
            CmnMessage.showMessage("是否删除此信息？", MSG_TYPE_CONFIRM, this.deleteData.bind(this));
        }
    },
    //删除处理
    deleteData: function () {
        this.sendAjaxByList("/Master/DeleteEmployeeInfo", this.tableIns.checkedPKIDList, this.onClickDeleteCallback.bind(this));
    },
    //删除CallBack
    onClickDeleteCallback: function (response) {
        var json = this.jsonParse(response);
        if (json.result > 0) {
            CmnMessage.showMessage("删除成功.", MSG_TYPE_INFO, this.messageCallBack.bind(this));
        }
        else {
            CmnMessage.showMessage("删除失败！", MSG_TYPE_ERROR);
        }
    },
    //点击message框后处理事件
    messageCallBack: function () {
        this.getEmployeeList();
    },
    //查找员工信息
    onClick_search: function () {
        this.tableIns.pager.pageIndex = 1;
        this.getEmployeeList();
    },
    //给单元格做处理事件
    cellCallback: function (rowData, colName, rowNo) {
        if (colName == "employee_name") {
            return "<a href='#' onclick='goEmployeeInput(" + rowData.employee_id + ");'>" + rowData.employee_name + "</a>"
        }

        return rowData[colName];
    },
    //设置table的行颜色
    setRowClass: function (rowData, rowNo) {
        if (rowNo % 2 != 0) {
            return "even";
        }
        else {
            return "odd";
        }
    }
});

//点击姓名show出修改控件
function goEmployeeInput(employee_id) {
    employeeListIns.employeeInputIns.show(employeeListIns.getEmployeeList.bind(employeeListIns), employee_id);
}